<template>
	<view class="person-img">
		<image class="image" :src="url" mode="widthFix"></image>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				url: ''
			}
		},
		onNavigationBarButtonTap(e) {
			uni.showActionSheet({
				itemList: ['拍照', '从手机相册选择', '保存本地'],
				success: (e) => {
					if (e.tapIndex == 0) {
						uni.chooseImage({
						    count: 1, //默认9
						    sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
						    sourceType: ['camera '], //从相册选择
						    success: (res) =>{
								console.log(res.tempFilePaths)
						        this.$store.commit('setUploadUrl', res.tempFilePaths[0])
						        this.url = res.tempFilePaths[0]
							}
						});
					}
					
					if (e.tapIndex == 1) {
						uni.chooseImage({
						    count: 1, //默认9
						    sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
						    sourceType: ['album'], //从相册选择
						    success: (res) =>{
						        this.$store.commit('setUploadUrl', res.tempFilePaths[0])
						        this.url = res.tempFilePaths[0]
							}
					   });
					}
					if (e.tapIndex == 2) {
						uni.downloadFile({
						    url: this.userInfo.pic, //仅为示例，并非真实的资源
						    success: (res) => {
						        if (res.statusCode === 200) {
						           this.$u.toast('文件下载成功')
						        }
						    },
							fail: (err) => {
								 this.$u.toast('文件下载失败')
							}
						});
					}
				}
			})
		},
		onLoad() {
		  this.url = this.$store.state.userInfo.pic
		},
		methods: {
			
		}
	}
</script>

<style lang="scss">
.person-img {
	position: relative;
	width: 100%;
	height: 100%;
	background-color: $bg_color;
	.image {
		position: absolute;
		left: 50%;
		top: 50%;
		-webkit-transform: translate(-50%,-50%);
		transform: translate(-50%,-50%);
		max-height: 100%;
		max-width: 100%;
	}
}
</style>
